package org.example.day;

import java.util.Arrays;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/08/22 17:38
 */
public class Solution169 {


    public int majorityElement(int[] nums) {
        Arrays.sort(nums);
        int num = nums[0];
        int count = 1;
        for (int i = 1; i < nums.length; i++) {
            if(num == nums[i]) {
                count++;
            }else {
                num = nums[i];
                count = 1;
            }
            if(count > nums.length/2) {
                return num;
            }
        }
        return num;
    }

    public int majorityElement2(int[] nums) {
        Arrays.sort(nums);
        return nums[nums.length / 2];
    }

}
